package com.hzlj.position.locate.common.dto.reportCommon;

import cn.hutool.core.lang.Pair;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hzlj.position.config.common.dto.common.PositionHandleExtDTO;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import static com.fz.common.base.core.date.DateUtils.*;

/**
 * @author lifh
 * @date 2023/3/29 10:34
 **/
@Data
public class ReportHandleDTO {
    /**
     * 分库分表标识:顺序与ids对应
     */
    private List<Key> keys;

    /**
     * 处理状态,dict-HANDLE_STATUS
     */
    private String handleStatus = "2";

    /**
     * 异常处理时间，如果没有值，则取当前时间
     */
    private Date handleTime = new Date();
    /**
     * 异常处理内容
     */
    private PositionHandleExtDTO handleExt;

    @Data
    public static class Key {
        private String id;
        @JsonFormat(locale = LOCALE, timezone = TIME_ZONE, pattern = DATE_SHORT_FORMAT)
        private Date belongDay;
    }

    /**
     * 从keys转化来的ids
     */
    public List<String> ids() {
        return this.getKeys().stream().map(ReportHandleDTO.Key::getId).collect(Collectors.toList());
    }

    /**
     * 从keys获取的最小最大的belongDay
     */
    public Pair<Date, Date> minMaxBelongDay() {
        List<Date> belongDays = this.getKeys().stream().map(ReportHandleDTO.Key::getBelongDay).sorted().collect(Collectors.toList());
        Date min = belongDays.get(0);
        Date max = belongDays.get(belongDays.size() - 1);
        return new Pair<>(min, max);
    }

}
